package com.smarttiger.zero.logic;

import com.smarttiger.zero.admin.entity.ArgsModel;
import com.smarttiger.zero.admin.entity.DataSourceModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class BaseLogic {

    List<ArgsModel> argsModels;

    DataSourceModel dataSourceModel;

    public void setParamValue(String k, Object v){
        Map<String, Object> cv = InterfaceContext.paramContext.get();
        if(cv == null){
            cv = new HashMap<>();
        }
        cv.put(k,v);
        InterfaceContext.paramContext.set(cv);
    }

    public Object getParamValue(String k){
        Map<String, Object> cv = InterfaceContext.paramContext.get();
        if(cv == null){
            return null;
        }
        return cv.get(k);
    }

    public void setCurrentValue(String k, Object v){
        Map<String, Object> cv = InterfaceContext.currentValueContext.get();
        if(cv == null){
            cv = new HashMap<>();
        }
        cv.put(k,v);
        InterfaceContext.currentValueContext.set(cv);
    }

    public Object getCurrentValue(String k){
        Map<String, Object> cv = InterfaceContext.currentValueContext.get();
        if(cv == null){
            return null;
        }
        return cv.get(k);
    }

    public void setResult(Object o){
        InterfaceContext.resultContext.set(o);
    }

    public abstract void logic();

    public List<ArgsModel> getArgsModels() {
        return argsModels;
    }

    public void setArgsModels(List<ArgsModel> argsModels) {
        this.argsModels = argsModels;
    }

    public DataSourceModel getDataSourceModel() {
        return dataSourceModel;
    }

    public void setDataSourceModel(DataSourceModel dataSourceModel) {
        this.dataSourceModel = dataSourceModel;
    }
}
